'use strict';
const express = require('express');
const router = express.Router();
const resUtil = require("../module/util/resUtil");
const reqUtil = require("../module/util/reqUtil");
const extend = require("extend");
const request = require('request');
const xml2json = require('basic-xml2json');
const WechatUtil = require('../module/util/WechatUtil');
const prizeTool = require('../module/util/prizeTool');

const EventService = require('../service/prize/EventService');
const RuleService = require('../service/prize/RuleService');
const RecordService = require('../service/prize/RecordService');
const CountService = require('../service/prize/CountService');
const logger = require('log4js').getLogger("sys");


router.get('/getVipInfoByWxid', function (req, res, next) {
    request({
        method: 'get',
        uri: `${global.config.pos.endpoint}/getVipInfoByWxid?wxId=${req.query.openId}`,
        json: true
    }, function (e, response, data) {
        if (!data) {
            res.send(resUtil.error({}));
            return;
        }
        let jsonStr = xml2json.parse(data);
        let json = JSON.parse(jsonStr.root.content);
        res.send(resUtil.success({result: json.ResultValue[0].errMsg.List[0]}))
    });

});

const redisclient = require('../module/util/redis');
router.get('/getUserData', function (req, res, next) {
    res.send(resUtil.success({result: req.session[req.query.publicId]}));
});

router.get('/flushRedisData', function (req, res, next) {
    //同步刷新redis的数据
    let openId = req.query.openId, publicId = req.query.publicId;
    global.util.getCustomerInfoByWxId(openId, publicId, function (json) {
        if (json && json.ResultValue) {
            redisclient.init();
            redisclient.set(openId + '#' + publicId, json.ResultValue[0].errMsg.List[0]);
            res.send(resUtil.success({result: json.ResultValue[0].errMsg.List[0]}));
        }
    }, function (data) {
        if (data && data.type === 'userNotFound') {
            redisclient.init();
            redisclient.del(openId + '#' + publicId);
            delete req.session[publicId];
            res.send(resUtil.success({notFound: 1}));
        } else {
            res.send(resUtil.success({result: req.session[publicId]}));
        }
    });
});

router.get('/cardSavingQuery', function (req, res, next) {
    request({
        method: 'get',
        uri: `${global.config.pos.endpoint}/cardSavingQuery?cardCode=${req.query.cardCode}&startDate=${req.query.startDate}&endDate=${req.query.endDate}`,
        json: true
    }, function (e, response, data) {
        if (!data) {
            res.send(resUtil.error({}));
            return;
        }
        let jsonStr = xml2json.parse(data);
        let json = JSON.parse(jsonStr.root.content);
        //1 {"ResultCode":"1","ResultValue":[{"errMsg":"查询提示:没有找到查询结果"}]}
        //0 {"ResultCode":"0","ResultValue":[{"errMsg":{"currSaving":164.80,"flow":[{"2017-08-10":"后台充值储值增加[400]"},{"2017-08-21":"前台储值卡付款储值减少[184]"}]}}]}
        if (json.ResultCode == "1") {
            res.send(resUtil.success({noresult: json.ResultValue[0].errMsg}))
        } else if (json.ResultCode == "0") {
            res.send(resUtil.success({result: json.ResultValue[0].errMsg.flow}))
        }

    });
});
router.get('/buildPosCode', function (req, res, next) {
    request({
        method: 'get',
        uri: `${global.config.pos.endpoint}/buildPosCode?cardCode=${req.query.cardCode}`,
        json: true
    }, function (e, response, data) {
        if (!data) {
            res.send(resUtil.error({}));
            return;
        }
        let jsonStr = xml2json.parse(data);
        let json = JSON.parse(jsonStr.root.content);
        console.log(json.ResultValue[0].errMsg);
        res.send(resUtil.success(json.ResultValue[0].errMsg))
    });
});
router.get('/cardPointQuery', function (req, res, next) {
    request({
        method: 'get',
        uri: `${global.config.pos.endpoint}/cardPointQuery?cardCode=${req.query.cardCode}&startDate=${req.query.startDate}&endDate=${req.query.endDate}`,
        json: true
    }, function (e, response, data) {
        if (!data) {
            res.send(resUtil.error({}));
            return;
        }
        let jsonStr = xml2json.parse(data);
        let json = JSON.parse(jsonStr.root.content);
        //1 {"ResultCode":"1","ResultValue":[{"errMsg":"查询提示:没有找到查询结果"}]}
        //0 {"ResultCode":"0","ResultValue":[{"errMsg":{"currSaving":164.80,"flow":[{"2017-08-10":"后台充值储值增加[400]"},{"2017-08-21":"前台储值卡付款储值减少[184]"}]}}]}
        if (json.ResultCode == "1") {
            res.send(resUtil.success({noresult: json.ResultValue[0].errMsg}))
        } else if (json.ResultCode == "0") {
            res.send(resUtil.success({result: json.ResultValue[0].errMsg.flow}))
        }
    });
});
router.get('/cardConsumSum', function (req, res, next) {
    request({
        method: 'get',
        uri: `${global.config.pos.endpoint}/cardConsumSum?cardCode=${req.query.cardCode}&startDate=${req.query.startDate}&endDate=${req.query.endDate}`,
        json: true
    }, function (e, response, data) {
        if (!data) {
            res.send(resUtil.error({}));
            return;
        }
        let jsonStr = xml2json.parse(data);
        let json = JSON.parse(jsonStr.root.content);
        //1 {"ResultCode":"1","ResultValue":[{"errMsg":"查询提示:没有找到查询结果"}]}
        //0 {"ResultCode":"0","ResultValue":[{"errMsg":{"currSaving":164.80,"flow":[{"2017-08-10":"后台充值储值增加[400]"},{"2017-08-21":"前台储值卡付款储值减少[184]"}]}}]}
        if (json.ResultCode == "1") {
            res.send(resUtil.success({noresult: json.ResultValue[0].errMsg}))
        } else if (json.ResultCode == "0") {
            res.send(resUtil.success({result: json.ResultValue[0].errMsg.flow}))
        }
    });
});
router.get('/getGiftInfo', function (req, res, next) {
    let cardCode = req.query.cardCard;
    console.log('进入礼券查询-----礼券号-');
    console.log('请求erp地址：' + `${global.config.pos.endpoint}/getGiftInfo?cardCode=${cardCode}`);
    request({
        method: 'get',
        uri: `${global.config.pos.endpoint}/getGiftInfo?cardCode=${cardCode}`,
        json: true
    }, function (e, response, data) {
        if (!data) {
            res.send(resUtil.error({}));
            return;
        }
        let date = new Date();
        let limitTime = date.setMonth(date.getMonth() - 3);
        let jsonStr = xml2json.parse(data);
        let json = JSON.parse(jsonStr.root.content);
        let list;
        console.log('礼券查询erp接口-----信息提示' + JSON.stringify(json.ResultValue[0].errMsg));
        console.log('--------------------------------------------');
        if (json.ResultCode == '1') {
            list = []
        } else {
            list = json.ResultValue[0].errMsg.List;
        }
        res.send(resUtil.success({lists: list}));
    });
});
router.get('/getResult', function (req, res, next) {
    console.log('=---------点击按钮');
    let id = req.query.eventId;
    let prizeResult;
    EventService.findById({}, id).then(event => {
        if (event._doc.needPoint == 0) {
            let curPoint = req.session[req.session.publicId].currPoint;
            console.log(curPoint);
            RuleService.find({}, {eventId: id}, 'eventId').then(ruleList => {
                console.log(ruleList);
                prizeTool.getPrizeResult(100, ruleList, req.session[req.session.publicId].openid).then(prizeResult => {
                    console.log('--type');
                    console.log(typeof prizeResult);
                    console.log(prizeResult, '=====抽奖结果123');
                    prizeResult = prizeResult.result;
                    let oa = event.officialAccount, expireTime = event.receiveDate;
                    CountService.find({}, {
                        customer: req.session[req.session.publicId].openid,
                        eventId: id,
                        officialAccount: oa
                    })
                        .then(countList => {
                            let sendResult = function (prizeResult, count) {
                                prizeTool.saveRecord(req.session[req.session.publicId], prizeResult, oa, expireTime, event._doc.needPoint, req.query.gameType)
                                    .then(result => {
                                        if (!result.curUserPoint) {
                                            result.curUserPoint = curPoint;
                                            req.session[req.session.publicId].currPoint = curPoint
                                        }
                                        if (prizeResult) {
                                            res.send(resUtil.success({
                                                result: prizeResult,
                                                customer: req.session[req.session.publicId],
                                                count: count.counter,
                                                addMsg: result
                                            }));
                                        } else {
                                            res.send(resUtil.success({
                                                result: event,
                                                count: count.counter,
                                                addMsg: {curUserPoint: curPoint}
                                            }));
                                        }
                                    }, err => {
                                        res.send(resUtil.success(err))
                                    });
                            };
                            if (countList.length == 0) {
                                let counter = {
                                    customer: req.session[req.session.publicId].openid,
                                    eventId: id,
                                    officialAccount: oa,
                                    counter: 1,
                                    vipName: req.session[req.session.publicId].vipName,
                                    cardCode: req.session[req.session.publicId].cardCode,
                                    mobile: req.session[req.session.publicId].mobile
                                };
                                CountService
                                    .save({}, counter).then(count => sendResult(prizeResult || event, count), err => logger.info(err))
                            } else {
                                CountService.updateById({}, countList[0]._id, {counter: countList[0].counter + 1})
                                    .then(count => {
                                        count.counter = count.counter + 1;
                                        sendResult(prizeResult || event, count);
                                    }, err => logger.info(err))
                            }
                        }, err => logger.info(err));
                }, err => {
                    console.log(err);
                });

            }, err => {
                logger.info(err);
            });
        } else {
            request({
                method: 'get',
                uri: `${global.config.pos.endpoint}/cardPointLottery?cardCode=${req.session[req.session.publicId].cardCode}&point=${event._doc.needPoint}&operType=0`,
                json: true
            }, function (e, response, data) {
                if (!data) {
                    res.send(resUtil.error({}));
                    return;
                }
                let jsonStr = xml2json.parse(data);
                let json = JSON.parse(jsonStr.root.content);
                if (json.ResultCode === '0') {
                    let curPoint = json.ResultValue[0].errMsg.currPoint;
                    console.log(curPoint);
                    RuleService.find({}, {eventId: id}, 'eventId').then(ruleList => {
                        prizeResult = prizeTool.getPrizeResult(100, ruleList, req.session[req.session.publicId].openid);
                        console.log(typeof prizeResult);
                        prizeResult.then(prizeResult => {
                            console.log(data);
                            console.log('ahha');
                            console.log(prizeResult, '=====抽奖结果');
                            prizeResult = prizeResult.result;
                            let oa = event.officialAccount, expireTime = event.receiveDate;
                            CountService.find({}, {
                                customer: req.session[req.session.publicId].openid,
                                eventId: id,
                                officialAccount: oa
                            })
                                .then(countList => {
                                    let sendResult = function (prizeResult, count) {
                                        prizeTool.saveRecord(req.session[req.session.publicId], prizeResult, oa, expireTime, event._doc.needPoint, req.query.gameType)
                                            .then(result => {
                                                if (!result.curUserPoint) {
                                                    result.curUserPoint = curPoint;
                                                    req.session[req.session.publicId].currPoint = curPoint
                                                }
                                                if (prizeResult) {
                                                    res.send(resUtil.success({
                                                        result: prizeResult,
                                                        customer: req.session[req.session.publicId],
                                                        count: count.counter,
                                                        addMsg: result
                                                    }));
                                                } else {
                                                    res.send(resUtil.success({
                                                        result: event,
                                                        count: count.counter,
                                                        addMsg: {curUserPoint: curPoint}
                                                    }));
                                                }
                                            }, err => {
                                                res.send(resUtil.success(err))
                                            });
                                        /*         if(prizeResult){
                                                     console.log('**************' + event._doc.needPoint);
                                                     prizeTool.saveRecord(req.session.userData, prizeResult,oa,expireTime,event._doc.needPoint,req.query.gameType)
                                                         .then(result => {
                                                             if(!result.curUserPoint){
                                                                 result.curUserPoint=curPoint;
                                                                 req.session.userData.currPoint=curPoint
                                                             }
                                                             res.send(resUtil.success({result:prizeResult, customer: req.session.userData,count:count.counter,addMsg:result}));
                                                         },err=>{
                                                             res.send(resUtil.success(err))
                                                         });
                                                 }else{

                                                     req.session.userData.currPoint=curPoint;
                                                     res.send(resUtil.success({result:event,count:count.counter,addMsg:{curUserPoint:curPoint}}));
                                                 }*/
                                    };
                                    if (countList.length == 0) {
                                        let counter = {
                                            customer: req.session[req.session.publicId].openid,
                                            eventId: id,
                                            officialAccount: oa,
                                            counter: 1,
                                            vipName: req.session[req.session.publicId].vipName,
                                            cardCode: req.session[req.session.publicId].cardCode,
                                            mobile: req.session[req.session.publicId].mobile
                                        };
                                        CountService
                                            .save({}, counter).then(count => sendResult(prizeResult || event, count), err => logger.info(err))
                                    } else {
                                        CountService.updateById({}, countList[0]._id, {counter: countList[0].counter + 1})
                                            .then(count => {
                                                count.counter = count.counter + 1;
                                                sendResult(prizeResult || event, count);
                                            }, err => logger.info(err))
                                    }
                                }, err => logger.info(err));
                        });
                        console.log(prizeResult.toString());
                        for (let key  in prizeResult) {   //variable 为属性名
                            console.log(key)   //name age
                            console.log(prizeResult[key]);
                        }


                    }, err => {
                        logger.info(err);
                    });
                } else {
                    res.send(resUtil.success({err: json.ResultValue[0].errMsg}));
                }
            });
        }

    }, err => {
    });

});
router.get('/getCoupon', function (req, res, next) {
    let prizeId = req.query['prizeId'];
    let gameType = req.query['gameType'];
    let curUser = req.session[req.session.publicId];

    RuleService.findById(curUser, prizeId, 'eventId').then(rule => {
        let now = new Date();
        if (rule.eventId.eventDateStart && rule.eventId.eventDateStart > now) {
            res.send(resUtil.error({message: '活动尚未开始，暂不能领取~~'}));
        } else if (rule.eventId.eventDateEnd && rule.eventId.eventDateEnd < now) {
            res.send(resUtil.error({message: '此活动已过期，不能领取~~'}));
        } else if (rule.remainCount === 0) {
            res.send(resUtil.error({message: 'Sorry, 此券已被领完，下次早点来哦~~'}))
        } else {
            new Promise((resolve, reject) => {
                logger.info('活动领券，奖项次数设定：', rule.prizeNumber);
                if (rule.prizeNumber && rule.prizeNumber > 0) {
                    RecordService.count(curUser, {prize: rule._id, customer: curUser.openid}).then(count => {
                        logger.info('活动领券，当前用户中奖次数：', count);
                        if (count >= rule.prizeNumber) {
                            reject({message: 'Sorry, 该礼券领取次数已达上限~~'});
                        } else {
                            resolve();
                        }
                    });
                } else {
                    resolve();
                }
            }).then(() => {
                new Promise((resolve, reject) => {
                    console.log(req.session[req.session.publicId].cardCode);
                    if (rule.eventId.needPoint === 0) {
                        resolve();
                    } else {
                        request({
                            method: 'get',
                            uri: `${global.config.pos.endpoint}/cardPointLottery?cardCode=${req.session[req.session.publicId].cardCode}&point=${rule.eventId.needPoint}&operType=0`,
                            json: true
                        }, function (e, response, data) {
                            if (!data) {
                                reject('网络异常，积分扣减失败');
                            } else {
                                let jsonStr = xml2json.parse(data);
                                let json = JSON.parse(jsonStr.root.content);
                                if (json.ResultCode === '0') {
                                    resolve();
                                } else {
                                    reject('积分扣减失败，' + json.ResultValue[0].errMsg);
                                }
                            }
                        });
                    }
                }).then(() => {
                    prizeTool.saveRecord(curUser, rule, rule.eventId.officialAccount, rule.eventId.receiveDate, rule.eventId.needPoint, gameType).then(result => {
                        let msg = '';
                        if (rule.eventId.needPoint === 0) {
                            msg = '恭喜领取成功，请前往我的优惠券中查看。';
                        } else {
                            msg = `成功使用${rule.eventId.needPoint}积分兑换优惠券一张，请前往我的优惠券中查看。`;
                        }
                        res.send(resUtil.success({message: msg}));
                    }).catch(err => {
                        logger.error(err);
                        res.send(resUtil.error({message: err.message || err}));
                    })
                }).catch(err => {
                    logger.error(err);
                    res.send(resUtil.error({message: err.message || err}));
                })
            }).catch(err => {
                res.send(resUtil.error(err));
            });
        }
    }).catch(err => {
        logger.error(err);
        res.send(resUtil.error(err));
    });
});
router.get('/loadEventRule', function (req, res, next) {
    let eventId = req.query.eventId;
    console.log(eventId + '================eventid');
    EventService.findById({}, eventId)
        .then(eventList => {
            console.log(eventList + '--------eventList');
            RuleService.find({}, {eventId: eventId}, '', {sort: 1})
                .then(ruleList => {
                    let oa = eventList.officialAccount;
                    CountService
                        .find({}, {
                            customer: req.session[req.session.publicId].openid,
                            eventId: eventId,
                            officialAccount: oa
                        })
                        .then(countList => {
                            let sendResult = function (counter) {
                                res.send(resUtil.success({event: eventList, rule: ruleList, count: counter}))
                            };
                            if (countList.length == 0) {
                                sendResult(0)
                            } else {
                                sendResult(countList[0].counter)
                            }
                        }, err => logger.info(err));
                }, err => {
                })
        }, err => {
        });
});
router.get('/getRecord', function (req, res, next) {
    let openId = req.query.openId;
    let eventId = req.query.eventId;
    RecordService
        .find({}, {customer: openId, eventId: eventId}, 'eventId prize officialAccount')
        .then(record => {
                res.send(resUtil.success({record: record}))
            },
            err => {
                res.send(resUtil.error({}))
            })
});
router.post('/register', function (req, res, next) {
    let userData = req.body;
    console.log('------进入注册，调ERP接口-----');
    console.log(userData);
    console.log('openid,publicId,gId，brandid,vipName,vipMobile,vipBirthday,vipAddress');
    console.log('------get调ERP地址接口-----');
    console.log(`${global.config.pos.endpoint}/createVipNew?vipName=${userData.vipName}&vipMobile=${userData.vipMobile}&vipBrand=${userData.brandId}&vipBirthday=${userData.vipBirthday}&vipAddress=${userData.vipAddress}&vipIdentityCode=&openid=${userData.openId}&orgCode=&publicId=${userData.publicId}&token=${userData.gId}&introCardCode=${userData['introCardCode'] || ''}`);
    request({
        method: 'get',
        uri: encodeURI(`${global.config.pos.endpoint}/createVipNew?vipName=${userData.vipName}&vipMobile=${userData.vipMobile}&vipBrand=${userData.brandId}&vipBirthday=${userData.vipBirthday}&vipAddress=${userData.vipAddress}&vipIdentityCode=&openid=${userData.openId}&orgCode=&publicId=${userData.publicId}&token=${userData.gId}&introCardCode=${userData['introCardCode'] || ''}`),
        json: true,
    }, function (e, response, data) {
        if (!data) {
            res.send(resUtil.error({}));
            return;
        }
        let jsonStr = xml2json.parse(data);
        if (jsonStr.root) {
            let json = JSON.parse(jsonStr.root.content);
            console.log('-------------ERP返回数据---');
            console.log(json.ResultValue[0]);
            //1 {"ResultCode":"1","ResultValue":[{"errMsg":"查询提示:没有找到查询结果"}]}
            //0 {"ResultCode":"0","ResultValue":[{"errMsg":{"currSaving":164.80,"flow":[{"2017-08-10":"后台充值储值增加[400]"},{"2017-08-21":"前台储值卡付款储值减少[184]"}]}}]}
            if (json.ResultCode === "0") {
                // res.redirect(req.viewParam.linkPath + '/login?openId=' + openId + '&orgCode=' + orgCode);
                res.send(resUtil.success({}));
            } else if (json.ResultCode === "2") {
                res.send(resUtil.error({resolve: `${json.ResultValue[0].errMsg}\n温馨提示：您的的姓名+手机号已注册过会员卡，有两种方法解决此类问题:\n1.请至会员绑定页面，绑定你已注册过的会员卡。\n2.本次注册请在姓名后面加数字，如：李明2017，谢谢`}));
            } else {
                res.send(resUtil.error({err: json.ResultValue[0].errMsg}));
            }
        } else {
            res.send(resUtil.error({err: data}));
        }
    });
});
router.post('/bind', function (req, res, next) {
    let userData = req.body;
    console.log('------进入注册，调ERP接口-----');
    console.log(userData);
    console.log('cardBrand,openid,publicId,gId,cardCode,mobile');
    console.log('------get调ERP地址接口-----');
    let url = encodeURI(`${global.config.pos.endpoint}/bindCardNew?cardCode=${userData.cardCode}&mobile=${userData.mobile}&openid=${userData.openId}&cardBrand=${userData.brandId}&publicId=${userData.publicId}&introCardCode=${userData['introCardCode'] || ''}&token=${userData.gId}`);
    console.log(url);
    request({
        method: 'get',
        uri: url,
        json: true,
    }, function (e, response, data) {
        if (!data) {
            res.send(resUtil.error({}));
            return;
        }
        console.log('-------------ERP返回原始数据---');
        console.log(data);
        let jsonStr = xml2json.parse(data);
        console.log('-------------ERP返回数据xml---');
        console.log(JSON.stringify(jsonStr));
        if (jsonStr.root) {
            let json = JSON.parse(jsonStr.root.content);
            console.log('-------------ERP返回数据---');
            console.log(json.ResultValue[0]);
            //1 {"ResultCode":"1","ResultValue":[{"errMsg":"查询提示:没有找到查询结果"}]}
            //0 {"ResultCode":"0","ResultValue":[{"errMsg":{"currSaving":164.80,"flow":[{"2017-08-10":"后台充值储值增加[400]"},{"2017-08-21":"前台储值卡付款储值减少[184]"}]}}]}
            if (json.ResultCode == "0" || json.ResultCode == '4') {
                // res.redirect(req.viewParam.linkPath + '/login?openId=' + openId + '&orgCode=' + orgCode);
                res.send(resUtil.success({}));
            } else {
                res.send(resUtil.error({err: json.ResultValue[0].errMsg}));
            }
        } else {
            res.send(resUtil.error({err: data}));
        }
    });
});
router.post('/modify', function (req, res, next) {
    let userData = req.body;
    let url = encodeURI(`${global.config.pos.endpoint}/modifyVip?vipCode=${userData.vipCode}&vipName=${userData.vipName}&vipMobile=${userData.vipMobile}&vipBirthday=${userData.vipBirthday}&vipSex=${userData.vipSex}&vipIdentityCode=&vipAddress=${userData.vipAddress}`);
    console.log(url);
    request({
        method: 'get',
        uri: url,
        json: true,
    }, function (e, response, data) {
        if (!data) {
            res.send(resUtil.error({}));
            return;
        }
        let jsonStr = xml2json.parse(data);
        let json = JSON.parse(jsonStr.root.content);
        console.log(json);
        console.log('result-------------');
        //1 {"ResultCode":"1","ResultValue":[{"errMsg":"查询提示:没有找到查询结果"}]}
        //0 {"ResultCode":"0","ResultValue":[{"errMsg":{"currSaving":164.80,"flow":[{"2017-08-10":"后台充值储值增加[400]"},{"2017-08-21":"前台储值卡付款储值减少[184]"}]}}]}
        if (json.ResultCode == "0") {
            // res.redirect(req.viewParam.linkPath + '/login?openId=' + openId + '&orgCode=' + orgCode);
            res.redirect(global.config.path.contextPath + `/view/index?openId=${userData.openId}&gId=${userData.gId}&publicId=${userData.publicId}&brand=${userData.brand}`)
        } else {
            res.send(resUtil.error({err: json.ResultValue[0].errMsg}));
        }
    });
});
router.get('/changeRecord', function (req, res, next) {
    RecordService.updateById(req.curUser, req.query._id, {
        awardFlag: 1
    }).then(data => {
        res.send(resUtil.success())
    });
});
router.post('/sign/:gId', function (req, res, next) {
    let user = req.body;
    let gId = req.params.gId;
    request({
        url: global.config.path.mengkePath + '/api/bonus/sign?token=' + gId,
        method: 'post',
        json: user
    }, function (err, resp, body) {
        res.send(body);
    })
});
router.get('/bonus/config/:gId', function (req, res, next) {
    let gId = req.params.gId;
    request({
        url: global.config.path.mengkePath + '/api/bonus/config?token=' + gId,
    }, function (err, resp, body) {
        res.send(body);
    })
});
router.get('/bonus/record/:gId', function (req, res, next) {
    let gId = req.params.gId;
    let openId = req.query.openId;
    request({
        url: global.config.path.mengkePath + `/api/bonus/record?token=${gId}&openId=${openId}`,
    }, function (err, resp, body) {
        res.send(body);
    })
});


router.get('/eventList', function (req, res, next) {
    var token = req.query.token,
        store = req.curUser && req.curUser.createOrgCode || '';

    request({
        method: 'get',
        uri: `${global.config.path.mengkePath}/api/prize/eventList?token=${token}&store=${store}`,
        json: true
    }, function (e, response, data) {
        if (!data) {

        } else {
            res.send(data);
        }
    });

});


module.exports = router;
